package servlet;

import utils.DBUtil;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet("/delete")
public class DeleteServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.接收执行编号
        String id = request.getParameter("id");
        //2.编写sql语句
        String sql = "delete from house_info where id=?";
        //3.调用工具类执行sql语句获得影响行数
        int i = DBUtil.update(sql, id);
        //4.使用影响行数判断添加删除是否成功
        if(i>0){
            //重定向，跳转刷新页面
            response.sendRedirect("/list");
        }else{
            //5.将提示信息添加到request域中
            request.setAttribute("msg","删除失败");
            //6.将集合转发给jsp显示
            request.getRequestDispatcher("/WEB-INF/msg.jsp").forward(request,response);
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
